//
//  HBHomeCtrl.m
//  HuoBao
//
//  Created by sky on 15/11/27.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "HBHomeCtrl.h"
#import "HBInvestCtrl.h"
#import "HBIdentifierCheckCtrl.h"
#import "HBAddBankCtrl.h"
#import "NetCenter.h"
#import "HBgetProductInfoParam.h"
#import "HBgetProductInfoParser.h"
#import "HBgetProductInfoItemInfo.h"
#import "HBLoginManager.h"
#import "HBGetUserStatusManager.h"
#import "HBSetTradpasswordCtrl.h"
#import "CustomTradePassword.h"
#import "CustomSuggestionAlert.h"
#import "HBHomeInviteFriendCtrl.h"
#import "HBHomeProductDetailCtrl.h"

#import "HBShakeGamesCtrl.h"
#import "HBGetRedManager.h"
#import "HBShakeResultCtrl.h"

#import "HBInvestManager.h"
#import "MJRefresh.h"
#import "HBOrangeHeader.h"
#define GetFinalResult(x,y,z,r) (IsIphone4?x:(IsIphone6P?r:(IsIphone5?y:z)))

#define RATEFONT       GetFinalResult(75,75,110,110)
#define TOTOP          GetFinalResult(10,33,33,33)
#define LINEHEIGHT     GetFinalResult(106/2,76,76,76)
#define TOLEFT         GetFinalResult(80,80,134/2,154/2)
#define RATETOTOP      GetFinalResult(23,23,_bleovi.size.height/5 - 2,_bleovi.size.height/5)
#define RATEHEIGHT     GetFinalResult(55,55,83,83)
#define JXITOTOP       GetFinalResult(15,33,75/2,75/2)
#define LINETOJX       GetFinalResult(13,13,25,25)
#define BTNTOLINE      GetFinalResult(11,11,20,20)
#define YUANWITH       GetFinalResult(7,7,10,10)
#define ADDRATEFONT    GetFinalResult(14,14,20,20)
#define ADDRATEBOLD    GetFinalResult(16,16,20,20)
#define ADDRATETOTOP   GetFinalResult(10,10,15,15)
#define BESTRATETOTOP  GetFinalResult(9,9,15,18)
#define JXTOLEFT       GetFinalResult(15,15,SCREEN_WIDTH / 4 - jixi.size.width,SCREEN_WIDTH / 4 - jixi.size.width/2 - 30)
#define TXTORIGHT      GetFinalResult(SCREEN_WIDTH - 15 - tixian.size.width,SCREEN_WIDTH - 15 - tixian.size.width,3 * SCREEN_WIDTH/4,3 * SCREEN_WIDTH/4  - tixian.size.width/2 + 30)


@interface HBHomeCtrl ()
{
    UIScrollView *_bgview;
    UIView *_bleovi;
    UIView  *_incomevi;
    UILabel *_incomelbl;
    UILabel *_addincomelbl;
    UILabel *_percent;
    UIImageView *_jlvi;
    UIButton *_bugBtn;
    UIImage *_jiangli;
}

@property (strong ,nonatomic)HBgetProductInfoItemInfo *iteminfo;
@property (nonatomic, strong) NSTimer *timer;
@property (nonatomic, assign) NSInteger num;

@end

@implementation HBHomeCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setUserInteractionEnabled:YES];
    // Do any additional setup after loading the view.
}


-(void)buildLayout{
    self.title = @"活宝";
    self.num = 0;

    
    _bgview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _bgview.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_bgview];
    
    UIView *lastbgview = [[UIView alloc]initWithFrame:CGRectMake(TOLEFT, TOTOP, SCREEN_WIDTH - TOLEFT * 2 , SCREEN_WIDTH - TOLEFT * 2)];
    lastbgview.backgroundColor = [LCCommon getColor:Main_BackGround_Color];
    lastbgview.layer.cornerRadius = lastbgview.size.width/2;
    lastbgview.layer.borderColor = [LCCommon getColor:@"3cc5fc"].CGColor;
    lastbgview.layer.borderWidth = 1.5;
    [_bgview addSubview:lastbgview];
    
    
    _bleovi = [[UIView alloc]initWithFrame:CGRectMake(TOLEFT + YUANWITH, TOTOP + YUANWITH, SCREEN_WIDTH - (TOLEFT * 2 + YUANWITH * 2), SCREEN_WIDTH - (TOLEFT * 2 + YUANWITH * 2))];
    _bleovi.backgroundColor = [LCCommon getColor:@"1f1f1f"];
    _bleovi.layer.cornerRadius = _bleovi.size.width/2;
    [_bgview addSubview:_bleovi];

    


    _incomelbl = [self LabelWithRect:CGRectMake(0, _bleovi.origin.y + RATETOTOP, SCREEN_WIDTH, RATEHEIGHT) textColor:[LCCommon getColor:@"fa9838"] textstr:@"" textfont:RATEFONT textstyle:NSTextAlignmentCenter];
//    _incomelbl.backgroundColor = [UIColor whiteColor];
    [_bgview addSubview:_incomelbl];
    
    
    
    _jiangli = [UIImage imageNamed:[self setimagewith:@"home_jiangli" index:1]];
    _jlvi = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2 - (_jiangli.size.width * 2 + 5)/2 , _incomelbl.origin.y + RATEHEIGHT + ADDRATETOTOP, _jiangli.size.width, _jiangli.size.height)];
    _jlvi.alpha = 0;
    _jlvi.image = _jiangli;
    [_bgview addSubview:_jlvi];
    
    _addincomelbl = [self LabelWithRect:CGRectMake(_jlvi.origin.x + _jlvi.width + 5, _jlvi.origin.y, SCREEN_WIDTH - (_jlvi.origin.x + _jlvi.width + 5), _jlvi.height) textColor:[LCCommon getColor:@"f34546"] textstr:@"" textfont:ADDRATEFONT textstyle:NSTextAlignmentLeft];
    _addincomelbl.font = [UIFont boldSystemFontOfSize:ADDRATEBOLD];
    //_addincomelbl.backgroundColor = [UIColor whiteColor];
    //_addincomelbl.adjustsFontSizeToFitWidth = YES;
    [_bgview addSubview:_addincomelbl];
    
    

    UIImage *informar = [UIImage imageNamed:[self setimagewith:@"home_bestrate" index:1]];
    UIImageView *infovi = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2 - informar.size.width/2, _jlvi.origin.y + _jlvi.height + BESTRATETOTOP , informar.size.width,informar.size.height)];
    infovi.image = informar;
    [_bgview addSubview:infovi];
    
//    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(lastbgview.origin.x , lastbgview.origin.y, lastbgview.size.width, lastbgview.size.height)];
    btn.backgroundColor = [UIColor clearColor];
    [btn addTarget:self action:@selector(tapToProInfo) forControlEvents:UIControlEventTouchUpInside];
    [_bgview addSubview:btn];
    
    
    UIImage *zhang  = [UIImage imageNamed:@"home_zhang"];
    UIImage *tixian = [UIImage imageNamed:@"home_tixian"];
    UIImage *jixi   = [UIImage imageNamed:@"home_jixi"];
    
    UIImageView *zhangvi = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2 - zhang.size.width/2, lastbgview.origin.y + lastbgview.size.height + JXITOTOP, zhang.size.width, zhang.size.height)];
    zhangvi.image = zhang;
    [_bgview addSubview:zhangvi];
    
    
    UIImageView *jixivi = [[UIImageView alloc]initWithFrame:CGRectMake(JXTOLEFT, zhangvi.origin.y, jixi.size.width, jixi.size.height)];
    jixivi.image = jixi;
    [_bgview addSubview:jixivi];
    
    
    UIImageView *tixianvi = [[UIImageView alloc]initWithFrame:CGRectMake(TXTORIGHT, jixivi.origin.y, tixian.size.width, tixian.size.height)];
    tixianvi.image = tixian;
    [_bgview addSubview:tixianvi];
    
    
    UIView *line = [self makeLinewithRect:CGRectMake(15, jixivi.origin.y + jixivi.size.height + LINETOJX, SCREEN_WIDTH - 30, .5) Color:[LCCommon getColor:@"585858"] addview:_bgview];
    
    [self makeLinewithRect:CGRectMake(SCREEN_WIDTH/2, line.origin.y + .5, .5, LINEHEIGHT) Color:[LCCommon getColor:@"585858"] addview:_bgview];
    
    [self makeLinewithRect:CGRectMake(15, line.origin.y + LINEHEIGHT, line.size.width, .5) Color:[LCCommon getColor:@"585858"] addview:_bgview];

    
    UIImage *yaoyao = [UIImage imageNamed:[self setimagewith:@"home_yao" index:0]];
    UIImage *firend = [UIImage imageNamed:[self setimagewith:@"home_firend" index:0]];

    
    UIButton *yaoBtn = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/4 - yaoyao.size.width/2, line.origin.y + LINEHEIGHT/2 - yaoyao.size.height/2, yaoyao.size.width, yaoyao.size.height)];
    [yaoBtn setBackgroundImage:yaoyao forState:UIControlStateNormal];
    [yaoBtn addTarget:self action:@selector(yaoBtnPress) forControlEvents:UIControlEventTouchUpInside];
    [_bgview addSubview:yaoBtn];
    
    
    UIButton *firBtn = [[UIButton alloc]initWithFrame:CGRectMake(3 * SCREEN_WIDTH / 4 - firend.size.width/2 - 10, yaoBtn.origin.y, firend.size.width, firend.size.height)];
    [firBtn setBackgroundImage:firend forState:UIControlStateNormal];
    [firBtn addTarget:self action:@selector(firBtnPress) forControlEvents:UIControlEventTouchUpInside];
    [_bgview addSubview:firBtn];
    
    
    _bugBtn = [[UIButton alloc]initWithFrame:CGRectMake(15, line.origin.y + LINEHEIGHT + BTNTOLINE, SCREEN_WIDTH - 30, 45)];
    [_bugBtn setTitle:@"立即买入" forState:UIControlStateNormal];
    _bugBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [_bugBtn setBackgroundColor:[LCCommon getColor:@"f34546"] forState:UIControlStateNormal];
    [_bugBtn setBackgroundColor:[LCCommon getColor:@"d43333"] forState:UIControlStateHighlighted];
    [_bugBtn addTarget:self action:@selector(pressToBuy) forControlEvents:UIControlEventTouchUpInside];
    _bugBtn.clipsToBounds = YES;
    _bugBtn.layer.cornerRadius = 4;
    [_bgview addSubview:_bugBtn];
    
    _bgview.contentSize = CGSizeMake(SCREEN_WIDTH, (_bugBtn.origin.y) + 45 + 30 + 45 + 64 + TABBAR_HEIGHT);
    
    
    __weak UIScrollView *tableView = _bgview;
    __weak typeof(self) weakSelf = self;
    
    // 下拉刷新
    tableView.mj_header = [HBOrangeHeader headerWithRefreshingBlock:^{
        
        [weakSelf requestToHomeData];
        
        //        // 模拟延迟加载数据，因此2秒后才调用（真实开发中，可以移除这段gcd代码）
        //        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //            // 结束刷新
        //            [tableView.mj_header endRefreshing];
        //        });
    }];
    
//    [_bgview.mj_header beginRefreshing];
    [self requestToHomeData];
}

#pragma mark - firBtnPress

-(void)firBtnPress{
    LLog(@"firBtnPress");
    
    if (![HBLoginManager sharedHBLoginManager].hasLogined)
    {
        [HBLoginManager didLoginOut];
        return;
    }
    
//    if (self.showBlock1) {
//        self.showBlock1(YES);
//        //测试用
//    }
//    [[[CustomTradePassword alloc] init] showTradPasswordAlertView];
//    NSString* topStatus = @"1";
//    NSDictionary* dic = [NSDictionary dictionaryWithObject:topStatus forKey:@"myindex"];
//    [[NSNotificationCenter defaultCenter] postNotificationName:@"setNewFream" object:dic];
    
    HBHomeInviteFriendCtrl *inviteFriendCtrl = [[HBHomeInviteFriendCtrl alloc]init];
    [self.nav pushViewController:inviteFriendCtrl animated:YES];
}


#pragma mark - yaoBtnPress

-(void)yaoBtnPress{
    LLog(@"yaoBtnPress");
    
    if (![HBLoginManager sharedHBLoginManager].hasLogined)
    {
        [HBLoginManager didLoginOut];
        return;
    }
    
    [CustomLoadingView hideHudForView:self.view];
    [CustomLoadingView showHudToView:[UIApplication sharedApplication].keyWindow];
    [HBGetRedManager requestToGetShakeRedTimesWithResult:^(BOOL isSuccess, NSString *msg, NSError *error, int times) {
        [CustomLoadingView hideHudForView:[UIApplication sharedApplication].keyWindow];
        if (isSuccess)
        {
            if (times!=0)
            {
                HBShakeGamesCtrl *shake = [[HBShakeGamesCtrl alloc]init];
                [self.nav pushViewController:shake animated:YES];
              
            }
            else
            {
                HBShakeResultCtrl *ctrl = [[HBShakeResultCtrl alloc]init];
                [self.nav pushViewController:ctrl animated:YES];
            }
        }
        else
        {
            DISSMISS_ERR(error?[error description]:msg);
        }
    }];
}

#pragma mark - pressToBuy

-(void)pressToBuy{
    LLog(@"pressToBuy");
    
    if (![HBLoginManager sharedHBLoginManager].hasLogined)
    {
        [HBLoginManager didLoginOut];
        return;
    }
    
//    [CustomLoadingView showHudToView:nil];
    [CustomLoadingView hideHudForView:self.view];
    [CustomLoadingView showHudToView:[UIApplication sharedApplication].keyWindow];
    [HBInvestManager requestToGetUserInvestLimitWithResult:^(BOOL isSuccess, NSString *msg, NSError *error) {
//        [CustomLoadingView hideHudForView:nil];
        [CustomLoadingView hideHudForView:[UIApplication sharedApplication].keyWindow];
        if (isSuccess)
        {

            if ([[HBInvestManager sharedHBInvestManager].userInvestLimitInfo.bindCardStatus integerValue])
            {
                HBInvestCtrl *investCtrl = [[HBInvestCtrl alloc]init];
                [self.nav pushViewController:investCtrl animated:YES];
            }
            else
            {
                HBAddBankCtrl *checkCtrl = [[HBAddBankCtrl alloc]init];
                checkCtrl.viewpageJumpingFrom = isFromInvestView;
                checkCtrl.isRealName = [[HBInvestManager sharedHBInvestManager].userInvestLimitInfo.identityStatus integerValue];
//                checkCtrl.investMoney = self.moneyTF.text;
//                checkCtrl.userInvestInfo = userInvestInfo;
                [self.nav pushViewController:checkCtrl animated:YES];
            }
            

        }
        else
        {
            DISSMISS_ERR(error?[error description]:msg);
        }
    }];
    
    
//    HBShakeResultCtrl *shakeResultCtrl = [[HBShakeResultCtrl alloc]init];
//    [self.nav pushViewController:shakeResultCtrl animated:YES];
    
    /*
    if ([HBGetUserStatusManager sharedHBGetUserStatusManager].isAllAuthor)
    {
        HBInvestCtrl *investCtrl = [[HBInvestCtrl alloc]init];
        [self.nav pushViewController:investCtrl animated:YES];
    }
    else
    {
        [CustomLoadingView showHudToView:nil];
        [HBGetUserStatusManager requestToGetUserStatusWithResult:^(BOOL isSuccess, NSString *msg, NSError *error) {
            [CustomLoadingView hideHudForView:nil];
            if ([HBGetUserStatusManager sharedHBGetUserStatusManager].isAllAuthor)
            {
                HBInvestCtrl *investCtrl = [[HBInvestCtrl alloc]init];
                [self.nav pushViewController:investCtrl animated:YES];
            }
            else
            {
                if (![[HBGetUserStatusManager sharedHBGetUserStatusManager].userStatusInfo.identityStatus integerValue])
                {
                    HBIdentifierCheckCtrl *checkCtrl = [[HBIdentifierCheckCtrl alloc]init];
                    [self.nav pushViewController:checkCtrl animated:YES];
                }
                else
                {
                    HBAddBankCtrl *bankCtrl = [[HBAddBankCtrl alloc]initWithNibName:NSStringFromClass([HBAddBankCtrl class]) bundle:nil];
                    [self.nav pushViewController:bankCtrl animated:YES];
//                    [[[CustomTradePassword alloc] init] showTradPasswordAlertView];
                }
            }
            
        }];
    }
     */

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



-(UILabel *)LabelWithRect:(CGRect)rect textColor:(UIColor *)color textstr:(NSString *)str textfont:(int)font textstyle:(NSTextAlignment)aligment{
    UILabel *label = [[UILabel alloc] initWithFrame:rect];
    label.textColor = color;
    label.text = str;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = aligment;
    label.numberOfLines = 0;
    return label;
}


-(UIView *)makeLinewithRect:(CGRect)rect Color:(UIColor *)color addview:(UIView *)vi{
    UIView *line = [[UIView alloc]initWithFrame:rect];
    line.backgroundColor = color;
    [vi addSubview:line];
    return line;
}

#pragma mark - requestToHomeData

-(void)requestToHomeData{
    HBgetProductInfoParam *param = [[HBgetProductInfoParam alloc]init];
    param.uid = [HBLoginManager sharedHBLoginManager].currentUserInfo.uid;
    param.token = [HBLoginManager sharedHBLoginManager].currentUserInfo.token;
//    [CustomLoadingView showHudToView:nil];
    [CustomLoadingView showHudToView:self.view];
    HBgetProductInfoParser *parser = [[HBgetProductInfoParser alloc]init];
    [NetCenter getDataFromURL:Method_getProductInfo params:param parser:parser result:^(ParserResult *myResult) {
//        [CustomLoadingView hideHudForView:nil];
        [CustomLoadingView hideHudForView:self.view];
        [_bgview.mj_header endRefreshing];
        if (myResult.code == 0)
        {
            HBgetProductInfoItemInfo *info = (HBgetProductInfoItemInfo *)myResult.result;
            self.iteminfo =  info;
            [self makeDataForUI];
        }
        else
        {
            DISSMISS_ERR(myResult.message);
        }
        
        
    } failure:^(NSError *error) {
//        [CustomLoadingView hideHudForView:nil];
        [_bgview.mj_header endRefreshing];
        [CustomLoadingView hideHudForView:self.view];
        DISSMISS_ERR([error description]);
    }];
}


-(void)requestToRateData{
    HBgetProductInfoParam *param = [[HBgetProductInfoParam alloc]init];
    param.uid = [HBLoginManager sharedHBLoginManager].currentUserInfo.uid;
    param.token = [HBLoginManager sharedHBLoginManager].currentUserInfo.token;
//    [CustomLoadingView showHudToView:nil];
    [CustomLoadingView showHudToView:self.view];
    HBgetProductInfoParser *parser = [[HBgetProductInfoParser alloc]init];
    [NetCenter getDataFromURL:Method_getProductInfo params:param parser:parser result:^(ParserResult *myResult) {
//        [CustomLoadingView hideHudForView:nil];
        [CustomLoadingView hideHudForView:self.view];
        if (myResult.code == 0)
        {
            HBgetProductInfoItemInfo *info = (HBgetProductInfoItemInfo *)myResult.result;
            self.iteminfo =  info;
            [self makeaddrate];
        }
        else
        {
            DISSMISS_ERR(myResult.message);
        }
        
        
    } failure:^(NSError *error) {
//        [CustomLoadingView hideHudForView:nil];
        [CustomLoadingView hideHudForView:self.view];
        DISSMISS_ERR([error description]);
    }];
}


#pragma mark - tapToProInfo

-(void)tapToProInfo{
    LLog(@"tapToProInfo");
    HBHomeProductDetailCtrl *productDetailCtrl = [[HBHomeProductDetailCtrl alloc]init];
    [self.nav pushViewController:productDetailCtrl animated:YES];
}


#pragma mark - incomevi


-(void)makeDataForUI{
    [self performSelectorInBackground:@selector(multiThread) withObject:nil];

    
    if (self.iteminfo.increaseRate.length == 0 || [self.iteminfo.increaseRate doubleValue] == 0) {
        
    }else
    {
        _jlvi.alpha = 1;
        _addincomelbl.text = [NSString stringWithFormat:@"+%.1f",[self.iteminfo.increaseRate doubleValue] * 100];
    }
}

#pragma mark - makeaddrate

-(void)makeaddrate{
    if (self.iteminfo.increaseRate.length == 0 || [self.iteminfo.increaseRate doubleValue] == 0) {
        
    }else
    {
        _jlvi.alpha = 1;
        _addincomelbl.text = [NSString stringWithFormat:@"+%.1f",[self.iteminfo.increaseRate doubleValue] * 100];
    }
}

- (void)multiThread
{
    if (![NSThread isMainThread]) {
        
        self.timer =[NSTimer timerWithTimeInterval:0.08
                                            target:self
                                          selector:@selector(getResults)
                                          userInfo:nil
                                           repeats:YES];
        //将定时器添加到runloop中
        [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSDefaultRunLoopMode];
        [[NSRunLoop currentRunLoop] run];
        LLog(@"多线程结束");
    }
}



-(void)getResults{
    LLog(@"getResults");
    //
    if (self.num > (int)([self.iteminfo.interestRate floatValue] * 100)) {
        [self.timer invalidate];
        
        return;
    }
    //

    NSString *nianhuaShouYiLvStr = [[NSString alloc]init];
    if (((int)([self.iteminfo.interestRate floatValue] * 10000) % 10) == 0) {
        if (((int)([self.iteminfo.interestRate floatValue] * 1000) % 10) == 0) {
            nianhuaShouYiLvStr = [NSString stringWithFormat:@"%.f%%",([self.iteminfo.interestRate floatValue] * 100)];
        }else{
            nianhuaShouYiLvStr = [NSString stringWithFormat:@"%.1f%%",([self.iteminfo.interestRate floatValue] * 100)];
        }
        
    }else{
        nianhuaShouYiLvStr = [NSString stringWithFormat:@"%.2f%%",([self.iteminfo.interestRate floatValue] * 100)];
    }
    
    NSMutableAttributedString *nianhuaAtt = [[NSMutableAttributedString alloc]initWithString:nianhuaShouYiLvStr];
    NSRange nianhuaRange = [nianhuaShouYiLvStr rangeOfString:@"%"];
    [nianhuaAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:25] range:nianhuaRange];
    _incomelbl.attributedText = nianhuaAtt;
    
    self.num ++;
}


-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.nav.navigationBar.translucent = NO;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeContSizeToTop:) name:@"setNewFream"  object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestToRateData) name:@"upDataForHome"  object:nil];
    
    
    NSString* status = @"0";
    NSDictionary* dic = [NSDictionary dictionaryWithObject:status forKey:@"index"];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"setTopLabel" object:dic];
    [self.navigationController popToRootViewControllerAnimated:YES];
}




-(void)changeContSizeToTop:(NSNotification *)noti{
    NSDictionary *dict = noti.object;
    if ([[dict objectForKey:@"myindex"] isEqualToString:@"1"]) {
        _bgview.contentSize = CGSizeMake(SCREEN_WIDTH, (_bugBtn.origin.y) + 45 + 30 + 45 + 64 + TABBAR_HEIGHT + 44);
    }else{
        _bgview.contentSize = CGSizeMake(SCREEN_WIDTH, (_bugBtn.origin.y) + 45 + 30 + 45 + 64 + TABBAR_HEIGHT);
    }

}




#pragma mark - setimage

-(NSString *)setimagewith:(NSString *)name index:(int)index{
    if (index == 1) {
        
        if (isIphone4or5) {
            name = [NSString stringWithFormat:@"%@_4",name];
        }else{
            
        }
        
    }else if(index == 0){
        if (IsIphone4) {
            name = [NSString stringWithFormat:@"%@_4",name];
        }else{
        
        }
    }
    return name;
}





/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
